# -*- coding: utf-8

from PyQt4 import QtGui, QtCore
from QConfiguration import Config, QConfiguration
from QDownloadProgress import QDownloadProgress

class QMainWindow(QtGui.QMainWindow):
	
	def __init__(self, parent):
		super(QMainWindow, self).__init__(parent)
		self.icons_path = Config()["general"].icons_path
		self.setWindowTitle(self.tr("PyLoad - Gerenciador de Downloads!"))
		self.setWindowIcon(QtGui.QIcon(self.icons_path + "/download.png"))
		
		self.create_toolbar()
		self.create_statusbar()
		
		self.mainFrame = QtGui.QFrame()
		self.mainLayout = QtGui.QVBoxLayout()
		self.mainFrame.setLayout(self.mainLayout)
		self.setCentralWidget(self.mainFrame)
		#self.scroll = QtGui.QScrollArea()
		#self.scroll.setWidget(self.mainFrame)
		#self.scroll.setWidgetResizable(True)
		
		self.download_list = []
		
		self.connect(self.btnNewDownload, QtCore.SIGNAL("clicked()"), self.on_btnNewDownload_clicked)
		self.connect(self.btnConfigure, QtCore.SIGNAL("clicked()"), self.on_btnConfigure_clicked)
		self.connect(self.btnExit, QtCore.SIGNAL("clicked()"), self.on_btnExit_clicked)
	
	def create_toolbar(self):
		self.toolBar = QtGui.QToolBar(self)
		self.addToolBar(self.toolBar)
		
		newDownloadIcon = QtGui.QIcon()
		newDownloadIcon.addFile(self.icons_path + "/download.png", QtCore.QSize(128, 128))
		configureIcon = QtGui.QIcon()
		configureIcon.addFile(self.icons_path + "/configure.png", QtCore.QSize(128, 128))
		exitIcon = QtGui.QIcon()
		exitIcon.addFile(self.icons_path + "/exit.png", QtCore.QSize(128, 128))
		
		self.btnNewDownload = QtGui.QToolButton(self.toolBar)
		self.btnNewDownload.setIcon(newDownloadIcon)
		self.btnNewDownload.setMinimumSize(64, 64)
		
		self.btnConfigure = QtGui.QToolButton(self.toolBar)
		self.btnConfigure.setIcon(configureIcon)
		self.btnConfigure.setMinimumSize(64, 64)
		
		self.btnExit = QtGui.QToolButton(self.toolBar)
		self.btnExit.setIcon(exitIcon)
		self.btnExit.setMinimumSize(64, 64)
		
		self.toolBar.addWidget(self.btnNewDownload)
		self.toolBar.addWidget(self.btnConfigure)
		self.toolBar.addWidget(self.btnExit)
	
	def create_statusbar(self):
		self.statusBar = QtGui.QStatusBar()
		self.setStatusBar(self.statusBar)
		self.statusBar.showMessage(self.tr("Bem Vindo!!!!"), 5*1000)
	
	def on_btnNewDownload_clicked(self):
		newDownload = QDownloadProgress()
		self.download_list.append(newDownload)
		self.mainLayout.addWidget(newDownload)
	
	def on_btnConfigure_clicked(self):
		QConfiguration(self).show()
	
	def on_btnExit_clicked(self):
		self.close()

if __name__ == "__main__":
	import sys
	app = QtGui.QApplication(sys.argv)
	mw = QMainWindow(None)
	mw.showMaximized()
	app.exec_()